# Cell type colors
cell_types <- unique(sobj$cell_typeDC)
names(cell_types) <- cell_types
type_cols <- theme_cols
names(type_cols) <- cell_types
type_cols <- type_cols[!is.na(names(type_cols))]
# Find all cell type markers
Idents(sobj) <- sobj %>%
FetchData("cell_typeDC")
all_type_marks <- sobj %>%
FindAllMarkers(only.pos = T) %>%
as_tibble() %>%
filter(p_val_adj < 0.05)
# Cell type UMAP
type_umap <- sobj %>%
plot_features(
feature = "cell_typeDC",
plot_cols = type_cols,
feat_levels = names(type_cols)
) +
guides(color = col_guide) +
blank_theme +
theme(
legend.position = "top",
legend.title = element_blank(),
legend.text = element_text(size = 10)
)
# Marker plots
for (i in seq_along(type_cols)) {
cat("\n### **", names(type_cols[i]), "**\n", sep = "")
type_marks <- all_type_marks %>%
filter(cluster == names(type_cols[i]))
type_marks_fig <- sobj %>%
create_marker_fig(
input_markers = type_marks,
type_id = "cell_typeDC",
input_umap = type_umap,
umap_color = type_cols[[i]],
box_colors = type_cols
)
# type_marks %>%
# kable() %>%
# kable_styling(fixed_thead = T) %>%
# print()
print(type_marks_fig)
cat("\n\n---\n\n<br>\n\n<br>\n\n")
}# Cell type colors
cell_clusts <- sobj@meta.data %>%
mutate(
type_clust = str_extract(cell_typeDC2, "^[0-9]+"),
type_clust = as.numeric(type_clust)
) %>%
arrange(cell_typeDC, type_clust) %>%
pull(cell_typeDC2) %>%
unique()
names(cell_clusts) <- cell_clusts
clust_cols <- theme_cols
names(clust_cols) <- cell_clusts
clust_cols <- clust_cols[!is.na(names(clust_cols))]
# Find all cell cluster markers
Idents(sobj) <- sobj %>%
FetchData("cell_typeDC2")
all_clust_marks <- sobj %>%
FindAllMarkers(only.pos = T) %>%
as_tibble() %>%
filter(p_val_adj < 0.05)
# Cluster UMAP
clust_umap <- sobj %>%
plot_features(
feature = "cell_typeDC2",
plot_cols = clust_cols,
feat_levels = names(clust_cols)
) +
guides(color = col_guide) +
blank_theme +
theme(
legend.position = "top",
legend.title = element_blank(),
legend.text = element_text(size = 10)
)
# Cluster plots
for (i in seq_along(clust_cols)) {
cat("\n### **", names(clust_cols[i]), "**\n", sep = "")
clust_marks <- all_clust_marks %>%
filter(cluster == names(clust_cols[i]))
clust_marks_fig <- sobj %>%
create_marker_fig(
input_markers = clust_marks,
type_id = "cell_typeDC2",
input_umap = clust_umap,
umap_color = clust_cols[[i]],
box_colors = clust_cols
)
print(clust_marks_fig)
cat("\n\n---\n\n<br>\n\n<br>\n\n")
}# Find cluster markers separately for each cell type
sep_clust_marks <- cell_types %>%
map(find_sep_clust_markers, sobj) %>%
compact() %>%
bind_rows()
sep_clusts <- sep_clust_marks$cluster %>%
unique()
sep_clusts <- clust_cols[names(clust_cols) %in% sep_clusts] %>%
names()
# Cluster plots
for (i in seq_along(sep_clusts)) {
cat("\n### **", sep_clusts[i], "**\n", sep = "")
sep_marks <- sep_clust_marks %>%
filter(cluster == sep_clusts[i])
type <- sep_clusts[i] %>%
str_remove("^[0-9]+-")
sep_cols <- clust_cols[grepl(str_c("-", type), names(clust_cols))]
sep_cols <- c(sep_cols, "Other" = "#f0f0f0")
sep_clust_umap <- sobj %>%
FetchData(c("UMAP_1", "UMAP_2", "cell_typeDC", "cell_typeDC2")) %>%
as_tibble(rownames = "cell_id") %>%
mutate(cell_typeDC2 = if_else(cell_typeDC != type, "Other", cell_typeDC2)) %>%
plot_features(
feature = "cell_typeDC2",
plot_cols = sep_cols,
feat_levels = names(sep_cols)
) +
guides(color = col_guide) +
blank_theme +
theme(
legend.position = "top",
legend.title = element_blank(),
legend.text = element_text(size = 10)
)
sep_clust_marks_fig <- sobj %>%
create_marker_fig(
input_markers = sep_marks,
type_id = "cell_typeDC2",
input_umap = sep_clust_umap,
umap_color = sep_cols[sep_clusts[i]],
box_colors = sep_cols,
cell_type = type
)
print(sep_clust_marks_fig)
cat("\n\n---\n\n<br>\n\n<br>\n\n")
}